<?php

    class x_denegats {
        protected $db_man;
        protected $select = "select id_denegat, clau, mac from x_denegats";
        protected $delete = "delete from x_denegats where clau='%s' and mac='%s'";
        protected $insert = "insert into x_denegats(clau, mac) values ('%s', '%s')";
        
        function x_denegats($dbm) {
            $this->db_man = $dbm;
        }
        
        function add_denegat($clau, $mac) {
            return ($this->db_man->do_dml(sprintf($this->insert, $clau, $mac)));
        }
        
        function delete_denegat($clau, $mac) {
            return ($this->db_man->do_dml(sprintf($this->delete, $clau, $mac)));
        }
        
        function get_denegats() {
            $csr = $this->db_man->do_query($this->select);
            return ($csr);
        }
        
        function is_valid_mac($mac) {
            if (preg_match("/^[0-9a-fA-F]{2}(?=([:;.]?))(?:\\1[0-9a-fA-F]{2}){5}$/", $mac)){
                return true;
            } else {
                return false;
            }
        }
        
    }

?>